﻿@{
    ViewBag.Title = ViewBag.ID != 0 ? "编辑攻略" : "添加攻略";
}
<h3>@(ViewBag.ID != 0 ? "编辑攻略" : "添加攻略")</h3>
<div style="padding-left:50px;">
    <hr />
        <table class="tb" style="padding:5px;width:500px;">
            <tbody>
                <tr>
                    <td align="center"><span>地点：</span></td>
                    <td><input type="text" id="txtDestination" style="width:300px;" value ="@Model.Destination" ></td>
                </tr>
                <tr>
                    <td align="center"><span>链接地址：</span></td>
                    <td><input type="text" id="txtLink" style="width:300px;" value ="@Model.Link"></td>
                </tr>
                <tr>
                    <td align="center"><span>标题文字：</span></td>
                    <td><input type="text" id="txtTitle" style="width:300px;" value ="@Model.Title"></td>
                </tr>
            </tbody>
        </table>
    <hr />
    <table style="text-align :center;width:500px;">
        <tbody>
            <tr>
                <td>
                    <input type="button" value="@(ViewBag.ID != 0 ? "编辑" : "添加")" id="btnAdd" style="width:60px;">
                    <input type="button" value="返回" id="btnReturn" onclick="javascript: window.history.go(-1);" style="width:60px;">
                </td>
            </tr>
        </tbody>
    </table>
    <hr />
</div>
<script type="text/javascript">

    $("#btnAdd").bind("click", function () {
        edit();
    });

    function edit() {
        var txtDestination = $("#txtDestination").val();
        var txtLink = $("#txtLink").val();
        var txtTitle = $("#txtTitle").val();

        if (txtDestination == "") {
            dlg.Msg.Inf("目的地不能为空");
            return;
        }
        if (txtTitle == "") {
            dlg.Msg.Inf("标题不能为空");
            return;
        }
        $.ajax({
            type: "post",
            url: "/manage/strategy/json_edit",
            data: {
                ID: @ViewBag.ID,
                Destination: txtDestination,
                Link: txtLink,
                Title: txtTitle
            },
            dataType: "json",
            timeout: 30000, //over time：30s
            beforeSend: function () {
                window.top.qibu.msgbox.loading("正在提交申请，请稍后... ...");
            },
            success: function (data) {
                window.top.qibu.msgbox.hide();
                if (data) {
                    dlg.Msg.Inf("操作成功");
                    setTimeout("window.history.go(-1)", 1000);
                }
                else {
                    dlg.Msg.Err("操作失败");
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                window.top.qibu.msgbox.hide();
                dlg.Msg.Err(errorThrown);
            }
        });
    }
</script>